/*
 * TransitionFiringCommand.java
 *
 * Created on 20 maj 2007, 22:22
 */

package edu.uj.petri.commands;

import edu.uj.petri.model.Marking;
import edu.uj.petri.model.Model;
import edu.uj.petri.model.Transition;
import edu.uj.petri.simulation.Simulation;
import java.util.ResourceBundle;

/**
 *
 * @author Piotrek
 */
public class TransitionFiringCommand extends Command {
    
    private Transition transition;
    private Model model;
    private Simulation simulation;
    private Marking oldMarking;
    
    /** Creates a new instance of TransitionFiringCommand */
    public TransitionFiringCommand(Transition t, Model m, Simulation simulation) {
        this.transition = t;
        this.model = m;
        this.simulation = simulation;
    }

    public String toString() {
        return String.format(ResourceBundle.getBundle("edu/uj/petri/messages").getString("firing_of_transition_%s"), transition.getName());
    }

    void execute() {
        oldMarking = model.getMarking();
        transition.fire();
        simulation.showAllActiveTransitions();
        simulation.pushFiredTransition(transition);
    }

    void undo() {
        model.applyMarking(oldMarking);
        simulation.showAllActiveTransitions();
        simulation.popFiredTransition();
    }

    boolean canBeCombined(Command c) {
        return false;
    }

    private static final long serialVersionUID = 2551432088202946562L;
    
}
